home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 2003 August / MW 8 2003 CD1.iso / Inside Macworld / Product News / gimp-1.2.4.sit / gimp-1.2.4 / plug-ins / perl / examples / repdup < prev    next >
Encoding:
Text File  |  2000-05-21  |  1.2 KB  |  48 lines

  1. #!/usr/app/bin/perl
  2.  
  3. eval 'exec /usr/app/bin/perl  -S $0 ${1+"$@"}'
  4.     if 0; # not running under some shell
  5.  
  6. use Gimp qw(:auto __ N_);
  7. use Gimp::Fu;
  8.  
  9. #Gimp::set_trace(TRACE_ALL);
  10.  
  11. register    "repdup",
  12.         "Repeats and duplicates a selection.",
  13.         "Hopefully self-explanatory...",
  14.         "Claes G Lindblad <claesg\@algonet.se>",
  15.         "Claes G Lindblad <claesg\@algonet.se>",
  16.         "990328",
  17.         N_"<Image>/Edit/Repeat & Duplicate...",
  18.         "*",
  19.         [
  20.         [PF_SPINNER, "repeats", "Number of repeats",
  21.             3, [1, 1000, 1] ],
  22.         [PF_SPINNER, "xoffset", "X-offset",
  23.             50, [-1000, 1000, 1] ],
  24.         [PF_SPINNER, "yoffset", "Y-offset",
  25.             50, [-1000, 1000, 1] ],
  26.         ],
  27.     sub {
  28.         my ($img, $layer, $repeats, $xoffset, $yoffset) = @_;
  29.  
  30.         eval { $img->undo_push_group_start };
  31.         @b  = gimp_selection_bounds($img);
  32.         my $w = $b[3] - $b[1];
  33.         my $h = $b[4] - $b[2];
  34.         gimp_edit_copy($layer);
  35.         gimp_selection_none($img);
  36.         for ($i = 0; $i < $repeats; $i++) {
  37.             $b[1] = $b[1] + $xoffset;
  38.             $b[2] = $b[2] + $yoffset;
  39.             gimp_rect_select($img, $b[1], $b[2], $w, $h, REPLACE, 0, 0);
  40.             $bit_bucket = gimp_edit_paste($layer, 0);
  41.             gimp_floating_sel_anchor($bit_bucket);
  42.             gimp_selection_none($img);
  43.         }
  44.         eval { $img->undo_push_group_end };
  45.         return $img;
  46.     };
  47. exit main;
  48.